//
//  DataEditController.swift
//  SwiftIOS
//
//  Created by XFB on 2019/10/17.
//  Copyright © 2019 fearless. All rights reserved.
//

import UIKit
import RxSwift

protocol DataDelegate {
    // 添加任务
    func addData(name: String)
    // 编辑任务
    func editData(name: String)
}

class DataEditController: UITableViewController {
    
    var delegate : DataDelegate?
    var name: String?
    var button = UIButton()
    
    @IBOutlet weak var inputTextField: UITextField!
    
    @IBAction func completeButtonClick(_ sender: Any) {
        // 局部变量
        if let name = inputTextField.text, !name.isEmpty {
            // 全局变量
            if self.name != nil {
                delegate?.editData(name: inputTextField.text!)
            } else {
                delegate?.addData(name: inputTextField.text!)
            }
        }
        navigationController?.popViewController(animated: true)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        inputTextField.text = name
        inputTextField.becomeFirstResponder()
        
        if name != nil {
            navigationItem.title = "编辑任务"
        }
    }
 
}
